import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'search_result_screen.dart';

class SearchScreen extends StatelessWidget {
  const SearchScreen({super.key});

  static const List<Map<String, String>> hotDramas = [
    {
      'title': '神级保安',
      'searches': '20.9万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '重生80年代当食神',
      'searches': '19.1万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '小乞丐十年后报恩',
      'searches': '16.6万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '昆仑神王',
      'searches': '15.2万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '重生霸王',
      'searches': '13万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '未破之局',
      'searches': '10.5万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '重返花样年华',
      'searches': '8.8万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
    {
      'title': '家有仙婿',
      'searches': '6.3万搜索',
      'imageUrl': 'https://via.placeholder.com/150'
    },
  ];

  @override
  Widget build(BuildContext context) {
    TextEditingController searchController = TextEditingController();

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.orange[300],
        elevation: 0,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.black),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        title: Container(
          height: 40.h,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(8.r),
          ),
          child: TextField(
            controller: searchController,
            decoration: InputDecoration(
              hintText: '搜索短剧',
              border: InputBorder.none,
              prefixIcon: Icon(Icons.search, color: Colors.grey),
              contentPadding: EdgeInsets.only(top: 4.h),
            ),
          ),
        ),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => SearchResultScreen(searchQuery: searchController.text),
                ),
              );
            },
            child: Text(
              '搜索',
              style: TextStyle(color: Colors.black, fontSize: 16.sp),
            ),
          ),
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(16.0.w),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Center(
              child: Text(
                '便捷搜索',
                style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.bold),
              ),
            ),
            SizedBox(height: 8.h),
            Center(
              child: Text(
                '海量热剧尽在掌握',
                style: TextStyle(fontSize: 14.sp, color: Colors.grey),
              ),
            ),
            SizedBox(height: 32.h),
            Text(
              '热搜短剧榜',
              style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold),
            ),
            Expanded(
              child: ListView.builder(
                itemCount: hotDramas.length,
                itemBuilder: (context, index) {
                  final drama = hotDramas[index];
                  Color indexColor;
                  if (index == 0) {
                    indexColor = Colors.red;
                  } else if (index == 1) {
                    indexColor = Colors.orange;
                  } else if (index == 2) {
                    indexColor = Colors.yellow[700]!;
                  } else {
                    indexColor = Colors.black;
                  }
                  return ListTile(
                    leading: Image.network(
                      drama['imageUrl']!,
                      width: 50.w,
                      height: 50.h,
                      fit: BoxFit.cover,
                    ),
                    title: Text(
                      drama['title']!,
                      style: TextStyle(fontSize: 16.sp),
                    ),
                    subtitle: Text(
                      drama['searches']!,
                      style: TextStyle(fontSize: 12.sp, color: Colors.grey),
                    ),
                    trailing: Text(
                      '${index + 1}',
                      style: TextStyle(
                        fontSize: 20.sp,
                        color: indexColor,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    onTap: () {
                      // 处理点击事件
                    },
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
